

function _GenContent(name, values) {
    let _str = `${name} {`;
    for(const prop in values) {
        _str += `${prop}:${values[prop]};`;
    }
    _str += `}
`;
    return _str;
}

export function Add(name, values) {
    const _idx = styleSheet.length;
    const _str = _GenContent(name, values);
    styleSheet.sheet.insertRule(_str, _idx);
    return _idx;
}

export function AddKeyframe(name, values){
    const _idx = styleSheet.length;

    let _str = `@keyframes ${name} {`;
    for(const prop in values) {
        _str += _GenContent(prop, values[prop]);
    }
    _str += `}`;

    styleSheet.sheet.insertRule(_str, _idx);
    return _idx;
}

export function Remove(index) {
    styleSheet.sheet.deleteRule(index);
}

let styleSheet = undefined;
if(document) {
    styleSheet = document.createElement('style');
    styleSheet.type = 'text/css';
    document.head.appendChild(styleSheet);
}

